package modulos.usuario.vista;

import java.sql.ResultSet;
import java.util.List;
import javax.swing.JOptionPane;
import modulos.usuario.modelo.Cuenta_Usuario;
import modelo.Especialidad;
import modelo.Persona;
import modulos.usuario.modelo.Usuario;
import vista.modelo.OperacionesVarias;

/**
 *
 * @author caesar
 */
public class iFrmMedico extends javax.swing.JInternalFrame {

    private List<Object[]> usuarioActual = null;
    private Cuenta_Usuario eCuenta_Usuario = new Cuenta_Usuario();
    private Persona ePersona = new Persona();
    private Cuenta_Usuario findCuenta_Usuario = new Cuenta_Usuario();
    private Usuario findUsuario = new Usuario();
    private Persona findPersona = new Persona();

    /**
     * Creates new form iFrmDatosMed
     */
    public iFrmMedico() {
        initComponents();
    }

    public iFrmMedico(List<Object[]> currentUser)//currentUser = UsuarioLogueado
    {
        initComponents();
        OperacionesVarias.cerrarVentanaEscape(this);
        this.usuarioActual = currentUser;
        cagarInfoUsuario();
        loadEspecialidades();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlNewDoc = new javax.swing.JPanel();
        lblEstudios = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtaEstudio = new javax.swing.JTextArea();
        lblActividad = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtaActividad = new javax.swing.JTextArea();
        pnlBotonInf = new javax.swing.JPanel();
        chkEditar = new javax.swing.JCheckBox();
        pnlBuscar = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        lbltxtUsuario = new javax.swing.JLabel();
        lbltxtIdCuenta = new javax.swing.JLabel();
        separadorUsr = new javax.swing.JSeparator();
        lblUsuario = new javax.swing.JLabel();
        pnlIdentification = new javax.swing.JPanel();
        txtApellido = new javax.swing.JTextField();
        lblApellidos = new javax.swing.JLabel();
        lblNombres = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        lblCedula = new javax.swing.JLabel();
        txtCedula = new javax.swing.JTextField();
        pnlLineas = new javax.swing.JPanel();
        txtTelefono = new javax.swing.JTextField();
        txtFax = new javax.swing.JTextField();
        txtMovil = new javax.swing.JTextField();
        lblFax = new javax.swing.JLabel();
        lblFax1 = new javax.swing.JLabel();
        lblTelefono = new javax.swing.JLabel();
        pnlEspecialidad = new javax.swing.JPanel();
        cmbGenero = new javax.swing.JComboBox();
        lblEspecialidad = new javax.swing.JLabel();
        lblEspecialidad1 = new javax.swing.JLabel();
        cmbEspecialidad = new javax.swing.JComboBox();
        btnCerrar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Datos usuario:");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/DoctorMale.png"))); // NOI18N
        setName("iFramePaciente");
        setPreferredSize(new java.awt.Dimension(850, 550));
        setVisible(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        pnlNewDoc.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        pnlNewDoc.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblEstudios.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblEstudios.setText("Estudios:");
        pnlNewDoc.add(lblEstudios, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 290, -1, 18));

        txtaEstudio.setBackground(new java.awt.Color(254, 237, 214));
        txtaEstudio.setColumns(20);
        txtaEstudio.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        txtaEstudio.setRows(5);
        jScrollPane1.setViewportView(txtaEstudio);

        pnlNewDoc.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 310, 750, 40));

        lblActividad.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblActividad.setText("Actividad:");
        pnlNewDoc.add(lblActividad, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 360, -1, -1));

        txtaActividad.setBackground(new java.awt.Color(254, 237, 214));
        txtaActividad.setColumns(20);
        txtaActividad.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        txtaActividad.setRows(5);
        jScrollPane2.setViewportView(txtaActividad);

        pnlNewDoc.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 380, 750, 40));

        pnlBotonInf.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        chkEditar.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        chkEditar.setText("Editar");
        chkEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkEditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlBotonInfLayout = new javax.swing.GroupLayout(pnlBotonInf);
        pnlBotonInf.setLayout(pnlBotonInfLayout);
        pnlBotonInfLayout.setHorizontalGroup(
            pnlBotonInfLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBotonInfLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(chkEditar)
                .addContainerGap(31, Short.MAX_VALUE))
        );
        pnlBotonInfLayout.setVerticalGroup(
            pnlBotonInfLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBotonInfLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chkEditar)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        pnlNewDoc.add(pnlBotonInf, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 30, -1, -1));

        pnlBuscar.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        btnGuardar.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/filesaveas.png"))); // NOI18N
        btnGuardar.setText("Actualizar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        lbltxtUsuario.setBackground(new java.awt.Color(209, 209, 255));
        lbltxtUsuario.setFont(new java.awt.Font("Ubuntu", 1, 14)); // NOI18N
        lbltxtUsuario.setForeground(new java.awt.Color(10, 87, 7));
        lbltxtUsuario.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbltxtUsuario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(132, 139, 235)));
        lbltxtUsuario.setFocusable(false);

        lbltxtIdCuenta.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lbltxtIdCuenta.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbltxtIdCuenta.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(132, 139, 235)));
        lbltxtIdCuenta.setFocusable(false);

        separadorUsr.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout pnlBuscarLayout = new javax.swing.GroupLayout(pnlBuscar);
        pnlBuscar.setLayout(pnlBuscarLayout);
        pnlBuscarLayout.setHorizontalGroup(
            pnlBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBuscarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbltxtIdCuenta, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(lbltxtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50)
                .addComponent(separadorUsr, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(70, 70, 70))
        );
        pnlBuscarLayout.setVerticalGroup(
            pnlBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBuscarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(separadorUsr)
                    .addComponent(lbltxtIdCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbltxtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnGuardar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlNewDoc.add(pnlBuscar, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, -1, -1));

        lblUsuario.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblUsuario.setText("Usuario:");
        pnlNewDoc.add(lblUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 10, 71, -1));

        pnlIdentification.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        txtApellido.setBackground(new java.awt.Color(254, 237, 214));

        lblApellidos.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblApellidos.setText("Apellidos:");

        lblNombres.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblNombres.setText("Nombres:");

        txtNombre.setBackground(new java.awt.Color(254, 237, 214));

        lblCedula.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblCedula.setText("Cédula:");

        txtCedula.setBackground(new java.awt.Color(254, 237, 214));
        txtCedula.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCedula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCedulaKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout pnlIdentificationLayout = new javax.swing.GroupLayout(pnlIdentification);
        pnlIdentification.setLayout(pnlIdentificationLayout);
        pnlIdentificationLayout.setHorizontalGroup(
            pnlIdentificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlIdentificationLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlIdentificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblCedula)
                    .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addGroup(pnlIdentificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNombres)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlIdentificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblApellidos)
                    .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21))
        );
        pnlIdentificationLayout.setVerticalGroup(
            pnlIdentificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlIdentificationLayout.createSequentialGroup()
                .addGroup(pnlIdentificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlIdentificationLayout.createSequentialGroup()
                        .addGroup(pnlIdentificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblNombres, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblApellidos, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlIdentificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtApellido, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlIdentificationLayout.createSequentialGroup()
                        .addComponent(lblCedula)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 17, Short.MAX_VALUE))
        );

        pnlNewDoc.add(pnlIdentification, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 97, 750, 70));

        pnlLineas.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlLineas.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        txtTelefono.setBackground(new java.awt.Color(254, 237, 214));
        txtTelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTelefonoKeyTyped(evt);
            }
        });
        pnlLineas.add(txtTelefono, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 20, 155, -1));

        txtFax.setBackground(new java.awt.Color(254, 237, 214));
        txtFax.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtFaxKeyTyped(evt);
            }
        });
        pnlLineas.add(txtFax, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 20, 173, -1));

        txtMovil.setBackground(new java.awt.Color(254, 237, 214));
        txtMovil.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtMovilKeyTyped(evt);
            }
        });
        pnlLineas.add(txtMovil, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 20, 164, -1));

        lblFax.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblFax.setText("Fax:");
        pnlLineas.add(lblFax, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 20, -1, -1));

        lblFax1.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblFax1.setText("Movil:");
        pnlLineas.add(lblFax1, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 20, -1, -1));

        lblTelefono.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblTelefono.setText("Teléfono:");
        pnlLineas.add(lblTelefono, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, -1, -1));

        pnlNewDoc.add(pnlLineas, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 230, 750, 60));

        pnlEspecialidad.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlEspecialidad.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cmbGenero.setBackground(new java.awt.Color(235, 234, 254));
        cmbGenero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Masculino", "Femenino" }));
        pnlEspecialidad.add(cmbGenero, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 20, 160, -1));

        lblEspecialidad.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblEspecialidad.setText("Genero:");
        pnlEspecialidad.add(lblEspecialidad, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 20, -1, -1));

        lblEspecialidad1.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N
        lblEspecialidad1.setText("Especialidad:");
        pnlEspecialidad.add(lblEspecialidad1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 20, -1, -1));

        cmbEspecialidad.setBackground(new java.awt.Color(235, 234, 254));
        pnlEspecialidad.add(cmbEspecialidad, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 20, 280, -1));

        pnlNewDoc.add(pnlEspecialidad, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 170, 750, 60));

        getContentPane().add(pnlNewDoc, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 800, 440));

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/agt_home.png"))); // NOI18N
        btnCerrar.setText("Cerrar");
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });
        getContentPane().add(btnCerrar, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 470, 95, -1));

        getAccessibleContext().setAccessibleDescription("");
        getAccessibleContext().setAccessibleParent(this);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cagarInfoUsuario() {
        try {
            if (usuarioActual.size() == 1) {
                for (Object[] o : usuarioActual) {
                    findCuenta_Usuario = (Cuenta_Usuario) o[0];
                    findUsuario = (Usuario) o[1];
                    findPersona = (Persona) o[2];
                }
                lbltxtIdCuenta.setText(String.valueOf(findCuenta_Usuario.getId()));
                txtCedula.setText(findUsuario.getCedula());//kk
                txtNombre.setText(findPersona.getNombre());
                txtApellido.setText(findPersona.getApellido());
                cmbEspecialidad.setSelectedItem(findUsuario.getEspecialidad());
                txtTelefono.setText(findPersona.getTelefono());
                txtFax.setText(findPersona.getFax());
                txtMovil.setText(findPersona.getCelular());
                txtaEstudio.setText(findUsuario.getEstudios());
                txtaActividad.setText(findUsuario.getActividad());
                lbltxtUsuario.setText(findCuenta_Usuario.getNomUsuario());
                cmbGenero.setSelectedItem(findUsuario.getGenero());
                
                chkEditar.setEnabled(true);
                this.setTitle(findCuenta_Usuario.getTipo());
            }
            setHabilitar(false);
        } catch (Exception ex) {
            ex.getMessage();
        }
    }

    private void loadEspecialidades() {
        try {
            if (txtCedula.getText().trim().compareTo("0000000000".trim()) == 0)//usr admin x defecto
            {
                cmbEspecialidad.addItem("SOPORTE-TECNICO".toUpperCase());
            } else if (findCuenta_Usuario.getTipo().trim().compareToIgnoreCase("ASISTENTE".trim()) == 0) {
                cmbEspecialidad.addItem("ASISTENTE".trim());
            } else {
                Especialidad eEspe = new Especialidad();
                for (Especialidad esp : eEspe.selectEspecialidades()) {
                    cmbEspecialidad.addItem(esp.getEspecialidad());
                }
            }
        } catch (Exception ex) {
            ex.getMessage();
        }
    }

    private void setHabilitar(boolean habilitar) {
        txtCedula.setEditable(habilitar);
        txtNombre.setEditable(habilitar);
        txtApellido.setEditable(habilitar);
        cmbGenero.setEnabled(habilitar);
        cmbEspecialidad.setEnabled(habilitar);
        txtTelefono.setEditable(habilitar);
        txtFax.setEditable(habilitar);
        txtMovil.setEditable(habilitar);
        txtaEstudio.setEditable(habilitar);
        txtaActividad.setEditable(habilitar);
    }

    private Persona getAtributosPersona() {
        Persona p = new Persona();
        p.setIdPersona(findPersona.getIdPersona());
        p.setNombre(txtNombre.getText().trim());
        p.setApellido(txtApellido.getText().trim());
        p.setTelefono(txtTelefono.getText().trim());
        p.setFax(txtFax.getText().trim());
        p.setCelular(txtMovil.getText());
        return p;
    }

    private Usuario getAtributosUsuario() {
        Usuario u = new Usuario();
        u.setIdPersona(findUsuario.getIdPersona());
        u.setCedula(txtCedula.getText());
        u.setEspecialidad(cmbEspecialidad.getSelectedItem().toString());
        u.setEstudios(txtaEstudio.getText().trim());
        u.setActividad(txtaActividad.getText().trim());
        u.setGenero(cmbGenero.getSelectedItem().toString());
        return u;
    }

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCerrarActionPerformed

    @SuppressWarnings("static-access")
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        try {
            if (lbltxtIdCuenta.getText().trim().length() != 0 && txtCedula.isEditable() == false && chkEditar.isSelected() == false) {
                JOptionPane.showMessageDialog(null, "Para actualizar debe activar la casilla Editar ...", "Actualizar", JOptionPane.WARNING_MESSAGE);
                return;
            }

            if (lbltxtIdCuenta.getText().trim().length() == 0 && lbltxtUsuario.getText().trim().length() == 0) {
                JOptionPane.showMessageDialog(null, "Los datos del usuario actual no han sido debidamente cargados \n y por lo tanto sus datos no se pueden actualizar. \nEl sistema debe reiniciarse ...", "Actualizar", JOptionPane.WARNING_MESSAGE);
                System.exit(0);
            }

            if (cmbEspecialidad.getItemCount() == 0) {
                JOptionPane.showMessageDialog(null, "Antes de actualizar debe configurar las posibles especialidades que se utilizarán...\nSeleccione menú Configuración-> Dependencias-> Especialidad", "Dependencias no encontradas", JOptionPane.WARNING_MESSAGE);
                return;
            }

            if ((txtCedula.getText().trim().length() == 0 || txtNombre.getText().trim().length() == 0 || txtApellido.getText().trim().length() == 0))//kk trm
            {
                JOptionPane.showMessageDialog(null, "Los campos cédula, nombre, apellido son requeridos ...", "Actualizar", JOptionPane.WARNING_MESSAGE);
                return;
            }
            if (ePersona.validadorDeCedula(txtCedula.getText().trim()) == false) {
                JOptionPane.showMessageDialog(null, "El número de cédula ingresado no es válido\n Vuelva a ingresar el número correcto...", "Actualizar", JOptionPane.WARNING_MESSAGE);
                return;
            }
            if (eCuenta_Usuario.validarAtributoDuplicado(findUsuario.getIdPersona(), txtCedula.getText().trim(), null, 0) != null)//verificar el ultimo param
            {
                JOptionPane.showMessageDialog(null, "El número de identificación " + txtCedula.getText() + " le corresponde a otro usuario \nIngrese otro número de cédula ...", "Actualizar", JOptionPane.WARNING_MESSAGE);
                return;
            }
            if (JOptionPane.showConfirmDialog(null, "¿Realmente desea actualizar sus datos?", "Actualizar", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) {
                if (eCuenta_Usuario.updateInfoUsuario(this.getAtributosPersona(), this.getAtributosUsuario()) == 1) {
                    setHabilitar(false);
                    chkEditar.setEnabled(true);//kk
                    chkEditar.setSelected(false);
                    //cagarInfoUsuario();//con las pruebas hechas a esta linea realmnt puede omitirsela?
                    JOptionPane.showMessageDialog(null, "Los datos se han actualizado correctamente ...", "Guardar", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(null, "Los datos no se han podido actualizar ...", "Guardar", JOptionPane.WARNING_MESSAGE);
                }
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Se ha producido una excepcion:\n" + ex.getMessage(), "Actualizar", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void chkEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkEditarActionPerformed
        if (chkEditar.isSelected()) {
            setHabilitar(true);
            if (txtCedula.getText().compareTo("0000000000") == 0) {
                txtCedula.setEditable(false);
            }
        } else {
            setHabilitar(false);
        }
    }//GEN-LAST:event_chkEditarActionPerformed

    private void txtCedulaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCedulaKeyTyped
        OperacionesVarias.ingresoSoloNumeros(evt);
    }//GEN-LAST:event_txtCedulaKeyTyped

    private void txtTelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoKeyTyped
        OperacionesVarias.ingresoSoloNumeros(evt);
    }//GEN-LAST:event_txtTelefonoKeyTyped

    private void txtFaxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFaxKeyTyped
        OperacionesVarias.ingresoSoloNumeros(evt);
    }//GEN-LAST:event_txtFaxKeyTyped

    private void txtMovilKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMovilKeyTyped
        OperacionesVarias.ingresoSoloNumeros(evt);
    }//GEN-LAST:event_txtMovilKeyTyped
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JCheckBox chkEditar;
    private javax.swing.JComboBox cmbEspecialidad;
    private javax.swing.JComboBox cmbGenero;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblActividad;
    private javax.swing.JLabel lblApellidos;
    private javax.swing.JLabel lblCedula;
    private javax.swing.JLabel lblEspecialidad;
    private javax.swing.JLabel lblEspecialidad1;
    private javax.swing.JLabel lblEstudios;
    private javax.swing.JLabel lblFax;
    private javax.swing.JLabel lblFax1;
    private javax.swing.JLabel lblNombres;
    private javax.swing.JLabel lblTelefono;
    private javax.swing.JLabel lblUsuario;
    private javax.swing.JLabel lbltxtIdCuenta;
    private javax.swing.JLabel lbltxtUsuario;
    private javax.swing.JPanel pnlBotonInf;
    private javax.swing.JPanel pnlBuscar;
    private javax.swing.JPanel pnlEspecialidad;
    private javax.swing.JPanel pnlIdentification;
    private javax.swing.JPanel pnlLineas;
    private javax.swing.JPanel pnlNewDoc;
    private javax.swing.JSeparator separadorUsr;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtFax;
    private javax.swing.JTextField txtMovil;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextArea txtaActividad;
    private javax.swing.JTextArea txtaEstudio;
    // End of variables declaration//GEN-END:variables
}
